package com.epoch.controller;

import com.epoch.entity.UserCourse;
import com.epoch.entity.vo.ResultInfo;
import com.epoch.exception.ParamsException;
import com.epoch.service.impl.UserCourseServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author mi
 */
@RestController
@Slf4j
public class UserCourseController {
    @Resource
    private UserCourseServiceImpl userCourseServiceImpl;
    /**
     * 收藏课程
     * @param userCourse
     */
    @PutMapping("epoch/user/saveCourse")
    public ResultInfo saveCourse(UserCourse userCourse){
        ResultInfo resultinfo=new ResultInfo();
        try{
            userCourseServiceImpl.saveCourse(userCourse);
        }catch(ParamsException p){
            p.printStackTrace();
            resultinfo.setCode(p.getCode());
            resultinfo.setMsg(p.getMsg());
        }catch(Exception e){
            e.printStackTrace();
            resultinfo.setCode(500);
            resultinfo.setMsg("收藏课程失败！请稍后重试");
        }
        return resultinfo;
    }
    /**
     * 删除课程
     * @param userCourse
     */
    @PutMapping("epoch/user/saveCourse")
    public ResultInfo deleteCourse(UserCourse userCourse){
        ResultInfo resultinfo=new ResultInfo();
        try{
            userCourseServiceImpl.deleteCourse(userCourse);
        }catch(ParamsException p){
            p.printStackTrace();
            resultinfo.setCode(p.getCode());
            resultinfo.setMsg(p.getMsg());
        }catch(Exception e){
            e.printStackTrace();
            resultinfo.setCode(500);
            resultinfo.setMsg("删除课程失败！请稍后重试");
        }
        return resultinfo;
    }
}
